#pragma once
#include <vector>
#include <map>
#include <memory>

#include <boost/asio.hpp>
#include "net/libgo.h"
#include "buffer.h"
#include "defines.h"

using namespace boost::asio;
using namespace boost::asio::ip;
using boost::system::error_code;

namespace libzq
{
	class ClientImpl;
	class ServerImpl
	{
	public:
		ServerImpl();
		virtual ~ServerImpl();
		virtual void start_serve(const char* host, uint16_t port); //开始接受连接
		virtual void stop(); // 停止服务

		virtual void connection_connected(shared_ptr<tcp::socket> sock); // 有新连接进来
		virtual void connection_disconnect(shared_ptr<ClientImpl> client); // 连接断开

		// 使用rabbitmq监听广播消息
		void boradcast(const char* host, const char* queue, const char* exchange, const string& exchange_type, const char* routing_key);
		virtual void on_boradcast(std::shared_ptr<MsgPacker> msg);
	protected:
		vector<shared_ptr<ClientImpl>> _clients; // 连接
	private:
		shared_ptr<tcp::acceptor> _acceptor;
		co_chan<bool> _stop_chan;
		bool _stop;
	};
}